package day21;

/**
 *
 * Student.java
 * @author wangbiao<br/>
 *         email:785497344@qq.com
 * @description 
 * @since 1.0.0
 * @date 2013-7-1下午10:43:09
 *
 */
public class Student implements Comparable<Student> {

	private String name;

	private int math;

	private int english;

	private int chinese;

	private int sum;

	public Student() {
		super();
	}

	public Student(String name, int math, int english, int chinese) {
		super();
		this.name = name;
		this.math = math;
		this.english = english;
		this.chinese = chinese;
		this.sum = math + english + chinese;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getMath() {
		return math;
	}

	public void setMath(int math) {
		this.math = math;
	}

	public int getEnglish() {
		return english;
	}

	public void setEnglish(int english) {
		this.english = english;
	}

	public int getChinese() {
		return chinese;
	}

	public void setChinese(int chinese) {
		this.chinese = chinese;
	}

	public int getSum() {
		return sum;
	}

	public void setSum(int sum) {
		this.sum = sum;
	}

	@Override
	public int hashCode() {
		return this.name.hashCode() + sum * 17;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Student) {
			throw new ClassCastException("类型不匹配");
		}
		Student student = (Student) obj;
		return this.name.equals(student.name) && (this.sum == student.sum);
	}

	@Override
	public int compareTo(Student s) {
		int num = this.sum - s.getSum();
		if (num == 0) {
			return this.name.compareTo(s.getName());
		}
		return num;
	}

	@Override
	public String toString() {
		return "Student [name=" + name + ", math=" + math + ", english="
				+ english + ", chinese=" + chinese + ", sum=" + sum + "]";
	}
	
	

}
